<template>
	<view class="animated fadeIn faster" style="height: 100vh;background-color: #ffffff;">
		<view class="status-bar-height"></view>
		<view class="d-flex d-flex-center" style="padding-top: 100rpx;padding-bottom: 100rpx;">
			<image :src="userinfo.avatar_file?.url" class="rounded10" style="width: 200rpx;height: 200rpx;"></image>
		</view>
		<view>
			<view class="i-item b-border d-flex d-flex-between d-flex-middle p-3 bg-fff">
				<text>昵称</text>
				<view class="d-flex d-flex-middle">
					<text class="mr-1">{{userinfo.nickname}}</text>
					<text class="iconfont icon-youjiantou"></text>
				</view>
			</view>
			<!-- <view class="i-item b-border d-flex d-flex-between d-flex-middle p-3 bg-fff">
				<text>性别</text>
				<view class="d-flex d-flex-middle">
					<text class="mr-1">女</text>
					<text class="iconfont icon-youjiantou"></text>
				</view>
			</view> -->
			<view class="i-item b-border d-flex d-flex-between d-flex-middle p-3 bg-fff">
				<text>手机号码</text>
				<view class="d-flex d-flex-middle">
					<text class="mr-1 colorhold">未绑定</text>
					<text class="iconfont icon-youjiantou"></text>
				</view>
			</view>
		</view>
		
		<view>
			<view class="i-item b-border d-flex d-flex-between d-flex-middle p-3 bg-fff">
				<text>清除缓存</text>
				<text class="iconfont icon-youjiantou"></text>
			</view>
		</view>
		<view>
			<view class="i-item b-border d-flex d-flex-between d-flex-middle p-3 bg-fff">
				<text>注销账号</text>
				<text class="iconfont icon-youjiantou"></text>
			</view>
		</view>
		<view class="mb-5">
			<view class="i-item b-border d-flex d-flex-between d-flex-middle p-3 bg-fff" @click="logout">
				<text>退出登录</text>
				<text class="iconfont icon-youjiantou"></text>
			</view>
		</view>
		
	</view>
</template>

<script>
	const uniIdCo = uniCloud.importObject("uni-id-co")
	export default {
		data() {
			return {
				userinfo:{
					_id:'',
					nickname:'',
					avatar_file:{
						url:''
					}
				}
			}
		},
		onReady() {
			let userinfo = uni.getStorageSync('uni-id-pages-userInfo')
			if(userinfo){
				this.userinfo = userinfo
			}
		},
		methods: {
			async logout(){
				if(uniCloud.getCurrentUserInfo().tokenExpired > Date.now()){
					try{
						await uniIdCo.logout()
					}catch(e){
						console.error(e);
					}
				}
				uni.removeStorageSync('uni_id_token');
				uni.setStorageSync('uni_id_token_expired', 0)
				uni.redirectTo({
					url: '/pages/login/login',
				});
			}
		}
	}
</script>

<style scoped>
.i-item{
	color: #555555;
}
.b-border{
	border-bottom:solid 1px rgba(204, 204, 204, .3);
}
</style>
